<template>
    <div class="editData">
        <div class="editor">编辑</div>
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="公司名称">
                <el-input size="mini" v-model="form.name" :placeholder="scope.name"></el-input>
            </el-form-item>
            
            <el-form-item label="招标公告">
                <el-input size="mini" v-model="form.tenderAnnouncement" :placeholder="scope.tenderAnnouncement"></el-input>
            </el-form-item>
            
            <el-form-item label="营业执照">
                <!-- <el-input v-model="form.city" :placeholder="scope.city"></el-input> -->
                <el-upload
                size="mini"
                class="avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload">
                <img v-if="imageUrl" :src="imageUrl" class="avatar">
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                </el-upload>
            </el-form-item>
            
            <el-form-item label="联系电话">
                <el-input size="mini" v-model="form.phone" :placeholder="scope.phone"></el-input>
            </el-form-item>
        </el-form>
        <div class="button">
            <el-button size="mini" @click="editShutDown(0)" class="cancel">取消</el-button>
            <el-button size="mini" @click="editShutDown(form)" class="determine" type="primary">确定</el-button>
        </div>
    </div>
</template>

<script>
import { mapState,mapMutations } from 'vuex'

export default {
    data(){
        return {
            form: {
                name:'',
                tenderAnnouncement:'',
                city:'',
                phone:''
            },
            imageUrl: ''
        }
    },
    computed:{
        ...mapState({
            scope:'scope',
        })
    },
    methods:{
        ...mapMutations({
            editShutDown:'editShutDown'
        }),
        handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
        },
        beforeAvatarUpload(file) {
            const isJPG = file.type === 'image/jpeg';
            const isLt2M = file.size / 1024 / 1024 < 2;

            if (!isJPG) {
            this.$message.error('上传头像图片只能是 JPG 格式!');
            }
            if (!isLt2M) {
            this.$message.error('上传头像图片大小不能超过 2MB!');
            }
            return isJPG && isLt2M;
        }
    },
}
</script>

<style lang="less" scoped>
.elbotton(){
    width: 100px;
}

.editData{
    width: 400px;
    height: 370px;
    background: rgb(255, 255, 255);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .button{
        width: 100%;
        height: 50px;
        display: flex;
        align-items: center;
        justify-content: space-evenly;
        .cancel{
            .elbotton();
        }
        .determine{
            .elbotton();
        }
    }
}

.editor{
    width: calc(100% - 20px);
    height: 50px;
    background: #409EFF;
    color: #FFFFFF;
    line-height: 50px;
    padding-left: 20px;
}
</style>

<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 50px;
    color: #8c939d;
    width: 200px;
    height: 100px;
    line-height: 50px;
    text-align: center;
    margin-top: 40px;
  }
  .avatar {
    width: 50px;
    height: 50px;
    display: block;
  }
</style>